package com.github.boluo1230.wechat.controller;

import com.github.boluo1230.wechat.base.ServerResponse;
import com.github.boluo1230.wechat.entity.MpApp;
import com.github.boluo1230.wechat.service.mp.MpAppService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Code Farmer
 * @date 2019/10/24 19:52
 */
@RestController
@RequestMapping("/mp/app")
@AllArgsConstructor
public class MpAppController {

    private final MpAppService mpAppService;

    /**
     * 获取公众号列表
     *
     * @return
     */
    @GetMapping("/list")
    public ServerResponse getList() {
        List<MpApp> mpAppList = mpAppService.findAll();
        return ServerResponse.createBySuccess(mpAppList);
    }

    /**
     * 获取公众号详情
     *
     * @param appId
     * @return
     */
    @GetMapping("/info")
    public ServerResponse getInfoByAppId(String appId) {
        return ServerResponse.createBySuccess(mpAppService.findMpApp(appId));
    }

    @GetMapping("/save")
    public ServerResponse saveMpApp(@RequestBody MpApp mpApp) {
        long result = mpAppService.saveMpApp(mpApp);
        return result > 0 ? ServerResponse.createBySuccess() : ServerResponse.createByError();
    }



}
